import { createWebHistory, createRouter } from "vue-router";
import Layout from "@/layout";

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
    hidden: true,
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error/404"),
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "index",
        component: () => import("@/views/index"),
        name: "Index",
        meta: { title: "首页", icon: "fa-home-lg-alt", affix: true },
      },
    ],
  },
  {
    path: "/basicDataManage",
    component: Layout,
    hidden: true,
    meta: { title: "基础数据管理", icon: "basicDataManage" },
    children: [
      {
        path: "cztData",
        component: () => import("@/views/basicDataManage/cztData/main"),
        name: "cztData",
        meta: { title: "承灾体数据", icon: "cztData" },
        children: [
          {
            path: 'singleBuilding',
            component: () => import("@/views/basicDataManage/cztData/singleBuilding/index"),
            name: "singleBuilding",
            meta: { title: "建筑物单体数据", icon: "singleBuilding", noCache: true },
          },
          {
            path: 'kilometerGrid',
            component: () => import("@/views/basicDataManage/cztData/kilometerGrid/index"),
            name: "kilometerGrid",
            meta: { title: "建筑物公里格网数据", icon: "kilometerGrid", noCache: true },
          },
          {
            path: 'buildingResetPrice',
            component: () => import("@/views/basicDataManage/cztData/buildingResetPrice/index"),
            name: "buildingResetPrice",
            meta: { noCache: true, title: "建筑物结构重置单价", icon: "buildingResetPrice" },
          },
          {
            path: 'czt-population',
            component: () => import("@/views/basicDataManage/cztData/population/index"),
            name: "czt-population",
            meta: { title: "人口数据", icon: "population", noCache: true },
          },
          {
            path: 'czt-economics',
            component: () => import("@/views/basicDataManage/cztData/economics/index"),
            name: "czt-economics",
            meta: { title: "经济数据", icon: "economics", noCache: true },
          },
        ]
      },
      {
        path: "dzwxxData",
        component: () => import("@/views/basicDataManage/dzwxxData/main"),
        name: "dzwxxData",
        meta: { title: "地震危险性数据", icon: "dzwxxData" },
        children: [
          {
            path: 'beyondProbability',
            component: () => import("@/views/basicDataManage/dzwxxData/beyond/index"),
            name: "beyondProbability",
            meta: { noCache: true, title: "超越概率地震危险性", icon: "beyondProbability" }
          },
          {
            path: 'occurProbability',
            component: () => import("@/views/basicDataManage/dzwxxData/occur/index"),
            name: "occurProbability",
            meta: { noCache: true, title: "发生概率地震危险性", icon: "occurProbability" }
          }
        ]
      },
      {
        path: "dzysxData",
        component: () => import("@/views/basicDataManage/dzysxData/index"),
        name: "dzysxData",
        meta: { noCache: true, title: "地震易损性数据", icon: "dzysxData" },
      },
      {
        path: "earthquakeImpactField",
        component: () => import("@/views/basicDataManage/earthquakeImpactField/index"),
        name: "earthquakeImpactField",
        meta: { noCache: true, title: "地震影响场数据", icon: "earthquakeImpactField" },
      },
      {
        path: "ysxData",
        component: () => import("@/views/basicDataManage/ysxData/index"),
        name: "ysxData",
        meta: { noCache: true, title: "易损性数据", icon: "ysxData" },
      },
    ]
  },
  {
    path: '/lifelineProject',
    component: Layout,
    hidden: true,
    children: [
      {
        path: "lifeline-taskManage",
        component: () => import("@/views/lifelineProject/taskManage/index"),
        name: "lifeline-taskManage",
        meta: { noCache: true, title: "任务管理" },
      },
      {
        path: "waterSupply",
        component: () => import("@/views/lifelineProject/waterSupply/index"),
        name: "waterSupply",
        meta: { noCache: true, title: "供水系统" },
      },
      {
        path: "gasSupply",
        component: () => import("@/views/lifelineProject/gasSupply/index"),
        name: "gasSupply",
        meta: { noCache: true, title: "供气系统" },
      },
      {
        path: "powerSupply",
        component: () => import("@/views/lifelineProject/powerSupply/index"),
        name: "powerSupply",
        meta: { noCache: true, title: "供电系统" },
      },
      {
        path: "traffic",
        component: () => import("@/views/lifelineProject/traffic/index"),
        name: "traffic",
        meta: { noCache: true, title: "交通系统" },
      },
      {
        path: "communication",
        component: () => import("@/views/lifelineProject/communication/index"),
        name: "communication",
        meta: { noCache: true, title: "通信系统" },
      },
    ]
  },
  {
    path: '/building',
    component: Layout,
    hidden: true,
    children: [
      {
        path: "taskManage",
        component: () => import("@/views/building/taskManage/index"),
        name: "TaskManage",
        meta: { noCache: true, title: "任务管理" },
      },
      {
        path: "building-confirm",
        component: () => import("@/views/building/confirm/index"),
        name: "building-confirm",
        meta: { title: "确定评估" },
        children: [
          {
            path: "seismic",
            component: () => import("@/views/building/confirm/seismic/index"),
            name: "seismic",
            meta: { noCache: true, title: "结构破坏-确定评估" },
          },
          {
            path: "personCasualties",
            component: () => import("@/views/building/confirm/personCasualties/index"),
            name: "personCasualties",
            meta: { noCache: true, title: "人员伤亡-确定评估" },
          },
          {
            path: "economicLosses",
            component: () => import("@/views/building/confirm/economicLosses/index"),
            name: "economicLosses",
            meta: { noCache: true, title: "经济损失-确定评估" },
          }
        ]
      },
      {
        path: "building-probability",
        component: () => import("@/views/building/probability/index"),
        name: "building-probability",
        meta: { title: "概率评估" },
        children: [
          {
            path: "resistEarthquakesPE",
            component: () => import("@/views/building/probability/seismic/index"),
            name: "resistEarthquakesPE",
            meta: { noCache: true, title: "结构破坏-概率评估" },
          },
          {
            path: "casualtiesPE",
            component: () => import("@/views/building/probability/personCasualties/index"),
            name: "casualtiesPE",
            meta: { noCache: true, title: "人员伤亡-概率评估" },
          },
          {
            path: "EconomicLossPD",
            component: () => import("@/views/building/probability/economicLosses/index"),
            name: "EconomicLossPD",
            meta: { noCache: true, title: "经济损失-概率评估" },
          }
        ]
      }
    ]
  },
  {
    path: "/building/confirm/",
    component: Layout,
    hidden: true,
    redirect: "/building/confirm/",
    children: [
      {
        path: "/building/confirm/seismic/map",
        component: () => import("@/views/building/confirm/seismic/map/index"),
        name: "buildingConfirmSeismicMap",
        meta: { noCache: true, title: "抗震能力-确定评估地图查看结果" },
      },
      {
        path: "/building/confirm/personCasualties/map",
        component: () => import("@/views/building/confirm/personCasualties/map/index"),
        name: "buildingConfirmPersonCasualtiesMap",
        meta: { noCache: true, title: "人员伤亡-确定评估地图查看结果" },
      },
      {
        path: "/building/confirm/economicLosses/map",
        component: () => import("@/views/building/confirm/economicLosses/map/index"),
        name: "buildingConfirmEconomicLossesMap",
        meta: { noCache: true, title: "经济损失-确定评估地图查看结果" },
      },
    ],
  },
  {
    path: "/building/probability/",
    component: Layout,
    hidden: true,
    redirect: "/building/probability/",
    children: [
      {
        path: "/building/probability/seismic/map",
        component: () => import("@/views/building/probability/seismic/map/index"),
        name: "buildingProbabilitySeismicMap",
        meta: { noCache: true, title: "抗震能力-概率评估地图查看结果" },
      },
      {
        path: "/building/probability/personCasualties/map",
        component: () => import("@/views/building/probability/personCasualties/map/index"),
        name: "buildingProbabilityPersonCasualtiesMap",
        meta: { noCache: true, title: "人员伤亡-概率评估地图查看结果" },
      },
      {
        path: "/building/probability/economicLosses/map",
        component: () => import("@/views/building/probability/economicLosses/map/index"),
        name: "buildingProbabilityEconomicLossesMap",
        meta: { noCache: true, title: "经济损失-概率评估地图查看结果" },
      },
    ],
  },
  {
    path: "/buildingRiskZoning/singleRiskZonation/",
    component: Layout,
    hidden: true,
    redirect: "/buildingRiskZoning/singleRiskZonation/",
    children: [
      {
        path: "/buildingRiskZoning/singleRiskZonation/confirm",
        component: () => import("@/views/buildingRiskZoning/singleRiskZonation/confirm/index"),
        name: "singleRiskZonationConfirm",
        meta: { noCache: true, title: "确定评估风险区划" },
      },
      {
        path: "/buildingRiskZoning/singleRiskZonation/confirm/map",
        component: () => import("@/views/buildingRiskZoning/singleRiskZonation/confirm/map/index"),
        name: "singleRiskZonationConfirmMap",
        meta: { noCache: true, title: "确定评估风险区划地图" },
      },
      {
        path: "/buildingRiskZoning/singleRiskZonation/probability",
        component: () => import("@/views/buildingRiskZoning/singleRiskZonation/probability/index"),
        name: "singleRiskZonationProbabilityMap",
        meta: { noCache: true, title: "概率评估风险区划" },
      },
    ],
  },
  {
    path: "/buildingRiskZoning/overallRiskZonation",
    component: Layout,
    hidden: true,
    redirect: "/buildingRiskZoning/overallRiskZonation",
    children: [
      {
        path: "/buildingRiskZoning/overallRiskZonation",
        component: () => import("@/views/buildingRiskZoning/overallRiskZonation/index"),
        name: "overallRiskZonationMap",
        meta: { noCache: true, title: "综合风险区划" },
      },
    ],
  },
  {
    path: "/buildingRiskZoning/standardSetting/",
    component: Layout,
    hidden: true,
    redirect: "/buildingRiskZoning/standardSetting/",
    children: [
      {
        path: "/buildingRiskZoning/standardSetting/single-index",
        component: () => import("@/views/buildingRiskZoning/standardSetting/single/index"),
        name: "single-index",
        meta: { noCache: true, title: "单指标风险区划设置" },
      },
      {
        path: "/buildingRiskZoning/standardSetting/overall-index",
        component: () => import("@/views/buildingRiskZoning/standardSetting/overall/index"),
        name: "overall-index",
        meta: { noCache: true, title: "综合指标风险区划设置" },
      },
    ],
  },
  {
    path: '/modelManage',
    component: Layout,
    hidden: true,
    children: [
      {
        path: "casualties",
        component: () => import("@/views/modelManage/casualties/index"),
        name: "casualties",
        meta: { noCache: true, title: "人员伤亡计算模型" },
      },
      {
        path: "economic",
        component: () => import("@/views/modelManage/economic/index"),
        name: "economic",
        meta: { noCache: true, title: "经济损失计算模型" },
      },
    ]
  },
  {
    path: "/searchExport/calculateExport/",
    component: Layout,
    hidden: true,
    redirect: "/searchExport/calculateExport/",
    children: [
      {
        path: "/searchExport/calculateExport/assess",
        component: () => import("@/views/searchExport/calculateExport/assess/index"),
        name: "assess",
        meta: { noCache: true, title: "评估/区划条件查询" },
      },
      {
        path: "/searchExport/calculateExport/fuzzy",
        component: () => import("@/views/searchExport/calculateExport/fuzzy/index"),
        name: "fuzzy",
        meta: { noCache: true, title: "条件模糊查询" },
      },
    ],
  },
  {
    path: "/searchExport/report/",
    component: Layout,
    hidden: true,
    redirect: "/searchExport/report/",
    children: [
      {
        path: "/searchExport/report/templateManage",
        component: () => import("@/views/searchExport/report/templateManage/index"),
        name: "templateManage",
        meta: { noCache: true, title: "报告模板管理" },
      },
      {
        path: "/searchExport/report/reportGenerate",
        component: () => import("@/views/searchExport/report/reportGenerate/index"),
        name: "reportGenerate",
        meta: { noCache: true, title: "报告管理" },
      },
    ],
  },
  {
    path: "/screenData",
    component: Layout,
    hidden: true,
    redirect: "noRedirect",
    meta: {title: "大屏关联数据管理"},
    children: [
      {
        path: "index3",
        component: () => import("@/views/screenData/index"),
        name: "reportModelManage",
        meta: { title: "大屏关联数据管理",noCache: true },
      },
    ],
  }
];

const router = createRouter({
  history: createWebHistory("fxqh"),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

export default router;
